<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            height: 3000px;
        }
        .nav{
            /* 粘性定位 */
            position: static;
            top: 0;
            /* 子要盒子距离可视区域的最上沿为0，就会变成黏性定位 */
            width: 800px;
            height: 50px;
            background-color: rebeccapurple;
            margin: 100px auto;
        }
    </style>
</head>
<body>
    <div class="nav">
        我是导航栏
    </div>
</body>
</html>